from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-11-24 16:34:14.015874
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 24, Nov, 2021
Time: 16:34:18
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2114
Nobs: 485.000 HQIC: -47.6828
Log likelihood: 5533.40 FPE: 1.44261e-21
AIC: -47.9879 Det(Omega_mle): 1.20054e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.392501 0.084391 4.651 0.000
L1.Burgenland 0.092266 0.044975 2.052 0.040
L1.Kärnten -0.116378 0.023007 -5.058 0.000
L1.Niederösterreich 0.158459 0.093497 1.695 0.090
L1.Oberösterreich 0.119734 0.094970 1.261 0.207
L1.Salzburg 0.281527 0.048155 5.846 0.000
L1.Steiermark 0.023165 0.062712 0.369 0.712
L1.Tirol 0.109431 0.050186 2.181 0.029
L1.Vorarlberg -0.084447 0.044204 -1.910 0.056
L1.Wien 0.031394 0.084497 0.372 0.710
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.020333 0.187683 0.108 0.914
L1.Burgenland -0.051567 0.100023 -0.516 0.606
L1.Kärnten 0.036229 0.051166 0.708 0.479
L1.Niederösterreich -0.212792 0.207935 -1.023 0.306
L1.Oberösterreich 0.476590 0.211212 2.256 0.024
L1.Salzburg 0.310444 0.107096 2.899 0.004
L1.Steiermark 0.097538 0.139469 0.699 0.484
L1.Tirol 0.308400 0.111611 2.763 0.006
L1.Vorarlberg 0.007860 0.098309 0.080 0.936
L1.Wien 0.017684 0.187919 0.094 0.925
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.241064 0.042831 5.628 0.000
L1.Burgenland 0.092404 0.022826 4.048 0.000
L1.Kärnten -0.004111 0.011676 -0.352 0.725
L1.Niederösterreich 0.216893 0.047452 4.571 0.000
L1.Oberösterreich 0.159122 0.048200 3.301 0.001
L1.Salzburg 0.034148 0.024440 1.397 0.162
L1.Steiermark 0.028248 0.031828 0.888 0.375
L1.Tirol 0.074987 0.025471 2.944 0.003
L1.Vorarlberg 0.057097 0.022435 2.545 0.011
L1.Wien 0.102310 0.042884 2.386 0.017
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183054 0.041550 4.406 0.000
L1.Burgenland 0.042143 0.022143 1.903 0.057
L1.Kärnten -0.011952 0.011327 -1.055 0.291
L1.Niederösterreich 0.142104 0.046033 3.087 0.002
L1.Oberösterreich 0.335156 0.046759 7.168 0.000
L1.Salzburg 0.097092 0.023709 4.095 0.000
L1.Steiermark 0.114984 0.030876 3.724 0.000
L1.Tirol 0.084856 0.024709 3.434 0.001
L1.Vorarlberg 0.055131 0.021764 2.533 0.011
L1.Wien -0.042045 0.041602 -1.011 0.312
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187287 0.080630 2.323 0.020
L1.Burgenland -0.044333 0.042970 -1.032 0.302
L1.Kärnten -0.036106 0.021981 -1.643 0.100
L1.Niederösterreich 0.120459 0.089330 1.348 0.178
L1.Oberösterreich 0.173307 0.090738 1.910 0.056
L1.Salzburg 0.252747 0.046009 5.493 0.000
L1.Steiermark 0.077443 0.059917 1.293 0.196
L1.Tirol 0.131266 0.047949 2.738 0.006
L1.Vorarlberg 0.107805 0.042234 2.553 0.011
L1.Wien 0.034637 0.080731 0.429 0.668
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067316 0.063523 1.060 0.289
L1.Burgenland 0.020376 0.033854 0.602 0.547
L1.Kärnten 0.051418 0.017318 2.969 0.003
L1.Niederösterreich 0.183788 0.070377 2.611 0.009
L1.Oberösterreich 0.344610 0.071486 4.821 0.000
L1.Salzburg 0.048693 0.036248 1.343 0.179
L1.Steiermark -0.007201 0.047204 -0.153 0.879
L1.Tirol 0.121306 0.037776 3.211 0.001
L1.Vorarlberg 0.058363 0.033274 1.754 0.079
L1.Wien 0.112332 0.063603 1.766 0.077
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188320 0.077582 2.427 0.015
L1.Burgenland 0.010355 0.041346 0.250 0.802
L1.Kärnten -0.060119 0.021150 -2.842 0.004
L1.Niederösterreich -0.119407 0.085954 -1.389 0.165
L1.Oberösterreich 0.218451 0.087309 2.502 0.012
L1.Salzburg 0.035210 0.044270 0.795 0.426
L1.Steiermark 0.273619 0.057652 4.746 0.000
L1.Tirol 0.488778 0.046137 10.594 0.000
L1.Vorarlberg 0.073706 0.040638 1.814 0.070
L1.Wien -0.105274 0.077680 -1.355 0.175
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.135478 0.085914 1.577 0.115
L1.Burgenland -0.012720 0.045787 -0.278 0.781
L1.Kärnten 0.064118 0.023422 2.737 0.006
L1.Niederösterreich 0.174912 0.095185 1.838 0.066
L1.Oberösterreich -0.074639 0.096685 -0.772 0.440
L1.Salzburg 0.222252 0.049025 4.533 0.000
L1.Steiermark 0.133159 0.063844 2.086 0.037
L1.Tirol 0.050921 0.051092 0.997 0.319
L1.Vorarlberg 0.142652 0.045003 3.170 0.002
L1.Wien 0.167432 0.086022 1.946 0.052
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.467698 0.047317 9.884 0.000
L1.Burgenland -0.002958 0.025217 -0.117 0.907
L1.Kärnten -0.013165 0.012900 -1.021 0.307
L1.Niederösterreich 0.174167 0.052423 3.322 0.001
L1.Oberösterreich 0.260232 0.053249 4.887 0.000
L1.Salzburg 0.017566 0.027000 0.651 0.515
L1.Steiermark -0.008873 0.035162 -0.252 0.801
L1.Tirol 0.069704 0.028139 2.477 0.013
L1.Vorarlberg 0.057074 0.024785 2.303 0.021
L1.Wien -0.019042 0.047376 -0.402 0.688
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.025772 0.091130 0.152189 0.135979 0.068497 0.081393 0.015871 0.206412
Kärnten 0.025772 1.000000 -0.037075 0.128689 0.047211 0.071990 0.457712 -0.082691 0.094459
Niederösterreich 0.091130 -0.037075 1.000000 0.274021 0.094609 0.258417 0.044410 0.142993 0.241256
Oberösterreich 0.152189 0.128689 0.274021 1.000000 0.185748 0.291649 0.158756 0.127515 0.169403
Salzburg 0.135979 0.047211 0.094609 0.185748 1.000000 0.125205 0.057766 0.110180 0.058665
Steiermark 0.068497 0.071990 0.258417 0.291649 0.125205 1.000000 0.134057 0.086858 0.008545
Tirol 0.081393 0.457712 0.044410 0.158756 0.057766 0.134057 1.000000 0.063084 0.126978
Vorarlberg 0.015871 -0.082691 0.142993 0.127515 0.110180 0.086858 0.063084 1.000000 -0.010419
Wien 0.206412 0.094459 0.241256 0.169403 0.058665 0.008545 0.126978 -0.010419 1.000000